package com.example.administrator.yuejian_2.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.CollectBean;
import com.example.administrator.yuejian_2.fragment.ActivityCollectListFragment;
import com.example.administrator.yuejian_2.fragment.ClubCollectListFragment;
import com.example.administrator.yuejian_2.fragment.ClubCourseFragment;
import com.example.administrator.yuejian_2.fragment.ClubIntroFragment;
import com.example.administrator.yuejian_2.fragment.ClubVideoFragment;
import com.example.administrator.yuejian_2.fragment.ContestCollectListFragment;
import com.example.administrator.yuejian_2.fragment.MasterCollectListFragment;
import com.example.administrator.yuejian_2.fragment.TrainCollectListFragment;
import com.example.administrator.yuejian_2.interservice.ClubService;
import com.example.administrator.yuejian_2.interservice.Const;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CollectListActivity extends AppCompatActivity {
    private ImageButton back;
    private int user_id;
    private RadioGroup radioGroup_collect;
//    private RadioButton train,club,activity,master,contest;
    private TrainCollectListFragment trainCollectListFragment;
    private ClubCollectListFragment clubCollectListFragment;
    private ActivityCollectListFragment activityCollectListFragment;
    private MasterCollectListFragment masterCollectListFragment;
    private ContestCollectListFragment contestCollectListFragment;

    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            fragmentManager = getSupportFragmentManager();
            setContentView(R.layout.activity_collect_list);
            SharedPreferences sharedPreferences = getSharedPreferences("userInfo",
                    Context.MODE_PRIVATE);
            user_id = sharedPreferences.getInt("user_id", 0);
            back = (ImageButton) findViewById(R.id.back);
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            radio();
        }




        public void radio(){
            radioGroup_collect = (RadioGroup) findViewById(R.id.radioGroup_collect);
            radioGroup_collect.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    switch (checkedId){
                        case R.id.train:
                            trainCollectListFragment = new TrainCollectListFragment();
                            replaceFragment(trainCollectListFragment);
                            break;
                        case R.id.club:
                            clubCollectListFragment = new ClubCollectListFragment();
                            replaceFragment(clubCollectListFragment);
                            break;
                        case R.id.activity:
                            activityCollectListFragment = new ActivityCollectListFragment();
                            replaceFragment(activityCollectListFragment);
                            break;
                        case R.id.master:
                            masterCollectListFragment = new MasterCollectListFragment();
                            replaceFragment(masterCollectListFragment);
                            break;
                        case R.id.contest:
                            contestCollectListFragment = new ContestCollectListFragment();
                            replaceFragment(contestCollectListFragment);
                            break;
                    }
                }
            });
            radioGroup_collect.check(R.id.train);

        }
        private void replaceFragment(Fragment fragment){
            fragmentManager= getSupportFragmentManager();
            fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.fragment_holder_collect,fragment);
            fragmentTransaction.commit();
        }




    }
